home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PlayeMovie.c
-
- Contains: QuickTime sample code
-
- Copyright: © 2000 by Apple Computer, Inc. All rights reserved
-
-
- */
-
-
- /************************************************************
- * *
- * INCLUDE FILES *
- * *
- *************************************************************/
-
-
- #if !defined(_MSC_VER) && _WIN32
- #include <Win32Headers.mch>
- #define TARGET_OS_WIN32 1
- #else
- #include <ConditionalMacros.h>
- #endif
-
- #if TARGET_OS_WIN32
- #include <QTML.h>
- #define STRICT
- #include <windows.h>
- #endif
-
-
- #include "MacTypes.h"
-
- #include "MacMemory.h"
- #include "Errors.h"
- #include "Fonts.h"
- #include "QuickDraw.h"
- #include "Resources.h"
- #include "Gestalt.h"
- #include "FixMath.h"
- #include "Sound.h"
- #include "string.h"
- #include "Movies.h"
- #include "ImageCompression.h"
- #include "Script.h"
- #include "TextUtils.h"
- #include "Processes.h"
-
- #include "PlayMovie.h"
- #include "PMUtilities.h"
- #include "PMWindow.h"
- #include "QTUtilities.h"
- #include "ComFramework.h"
-
- /************************************************************
- * *
- * FUNCTION PROTOTYPES *
- * *
- *************************************************************/
-
- #if TARGET_OS_MAC
- static void Utils_Macintosh_DisplayMsg(char *msg);
- static void InitMacToolbox (void);
- #else if TARGET_OS_WIN32
- static void Utils_Win32_DisplayMsg(char *msg);
- #endif
-
-
-
- /************************************************************
- * *
- * CONSTANTS *
- * *
- *************************************************************/
-
- #define kMsgDialogRsrcID 129
- #define kMsgItemID 3
-
- #define kPrompt "Enter the movie file name:"
- #define kFileName "MovieFile.mov"
-
- /*
- Sample Player's creator type since it is the movie player
- of choice. You can use your own creator type, of course.
- */
- #define kMyCreatorType FOUR_CHAR_CODE('TVOD')
-
-
- /************************************************************
- * *
- * FUNCTIONS *
- * *
- *************************************************************/
-
-
-
-
- /************************************************************
- * *
- * CheckError() *
- * *
- * Displays error message if an error occurred *
- * *
- *************************************************************/
-
- void CheckError(OSErr error, char *msg)
- {
- if (error == noErr)
- {
- return;
- }
- if (strlen(msg) > 0)
- {
- #if TARGET_OS_MAC
- Utils_Macintosh_DisplayMsg(msg);
- #else if TARGET_OS_WIN32
- Utils_Win32_DisplayMsg(msg);
- #endif
-
-
- ExitToShell();
-
- }
- }
-
- /************************************************************
- * *
- * OpenMovie() *
- * *
- * Open a movie in a new movie window and return true *
- * if successful. *
- * *
- *************************************************************/
-
- Boolean OpenMovie(void)
- {
- WindowObject myWindowObject = NULL;
- Movie myMovie = NULL;
- WindowReference myWindow = NULL;
- FSSpec myFSSpec;
- short myRefNum = kInvalidFileRefNum;
- short myResID = 0;
- OSType myTypeList[] = {kQTFileTypeMovie, kQTFileTypeQuickTimeImage};
- short myNumTypes = 2;
- GrafPtr mySavedPort;
- Rect myRect = {0, 0, 0, 0};
- Point myPoint;
- QTFrameFileFilterUPP myFileFilterUPP = NULL;
- OSErr myErr = noErr;
-
- #if TARGET_OS_MAC
- myNumTypes = 0;
- #endif
-
- GetPort(&mySavedPort);
-
- // Prompt the user for a movie file
- myFileFilterUPP = QTFrame_GetFileFilterUPP((ProcPtr)QTFrame_FilterFiles);
- myErr = QTFrame_GetOneFileWithPreview(myNumTypes, (QTFrameTypeListPtr)myTypeList, &myFSSpec, myFileFilterUPP);
- if (myFileFilterUPP != NULL)
- DisposeNavObjectFilterUPP(myFileFilterUPP);
- if (myErr != noErr)
- goto bail;
-
- // Step 1.
- // Insert OpenMovieFile.clp here...
-
- if (myErr != noErr)
- goto bail;
-
- // Open the first movie from the file
- myResID = 0;
-
- // Step 2.
- // Insert NewMovieFromFile.clp here...
-
- if (myErr != noErr)
- goto bail;
-
- // At this point myMovie should be a valid Movie
- // close the movie file as we no longer need it
-
- // Step 3.
- // Insert CloseMovieFile.clp here...
-
- // For this lab we close the file in the previous call, set myRefNum
- // to kInvalidFileRefNum so QTShell will not attempt to close the file again later
- myRefNum = kInvalidFileRefNum;
-
- // Set the default progress procedure for the movie
- SetMovieProgressProc(myMovie, // Movie specifier
- (MovieProgressUPP)-1, // UPP to a movie progress functions, -1 indicates default function
- 0); // Reference constant
-
- // Step 4.
- // Create the window for the movie
-
- myWindow = CreateMovieWindow();
-
- if (myWindow == NULL)
- goto bail;
- myWindowObject = QTFrame_GetWindowObjectFromWindow(myWindow);
- if (myWindowObject == NULL)
- goto bail;
- QTFrame_SetWindowTitleFromFSSpec(myWindow, &myFSSpec, true);
-
- // Make sure the movie file uses the window GWorld
-
- // Step 5.
- // Insert SetMovieGWorld.clp here...
-
- // Store movie info in the window record
- (**myWindowObject).fMovie = myMovie;
- (**myWindowObject).fController = NULL; // this sample does not use a movie controller
- (**myWindowObject).fGraphicsImporter = NULL;
- (**myWindowObject).fFileResID = myResID;
- (**myWindowObject).fFileRefNum = myRefNum;
- (**myWindowObject).fCanResizeWindow = false;
- (**myWindowObject).fIsDirty = false;
- (**myWindowObject).fIsQTVRMovie = QTUtils_IsQTVRMovie(myMovie);
- (**myWindowObject).fInstance = NULL;
- (**myWindowObject).fAppData = NULL;
- (**myWindowObject).fFileFSSpec = myFSSpec;
-
- // Step 6.
- // Size the window to fit the movie
-
- SizeWindowToMovie(myWindowObject);
-
- // Set the movie's play hints to allow dynamic resizing
-
- // Step 7.
- // Insert SetMoviePlayHints.clp here...
-
- // Step 8.
- // Set the movie's position, if it has a 'WLOC' user data atom
-
- myErr = GetWindowPositionFromFile(myMovie, &myPoint);
-
- // show the window
- #if TARGET_OS_MAC
- MoveWindow(myWindow, myPoint.h, myPoint.v, false);
- ShowWindow(myWindow);
- SelectWindow(myWindow); // make it front-most, since it's just been created
- InvalWindowRect(myWindow, GetWindowPortBounds(myWindow, &myRect));
- #endif
- #if TARGET_OS_WIN32
- SetWindowPos(myWindow, 0, myPoint.h, myPoint.v, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
- ShowWindow(myWindow, SW_SHOW);
- UpdateWindow(myWindow);
- #endif
-
- // Step 9.
- // Insert PrePrerollMovie.clp here...
-
- return(true);
-
- bail:
- if (myWindow != NULL)
- #if TARGET_OS_MAC
- DisposeWindow(myWindow);
- #endif
- #if TARGET_OS_WIN32
- SendMessage(ghWndMDIClient, WM_MDIDESTROY, (WPARAM)myWindow, 0L);
- #endif
-
- if (myMovie != NULL)
- DisposeMovie(myMovie);
-
- if (myRefNum != 0)
- CloseMovieFile(myRefNum);
-
- MacSetPort(mySavedPort); // restore the port that was active when this function was called
-
- return(false);
- }
-
-
- /************************************************************
- * *
- * FUNCTION: Utils_Macintosh_DisplayMsg *
- * *
- * PURPOSE: Displays Macintosh error messages *
- * *
- *************************************************************/
-
- #if TARGET_OS_MAC
- static void Utils_Macintosh_DisplayMsg(char *msg)
- {
- DialogPtr theDlog;
- Handle item = NULL;
- Rect box;
- StringPtr theMsg = QTUtils_ConvertCToPascalString(msg);
-
- theDlog = GetNewDialog(kMsgDialogRsrcID, NULL, (WindowPtr)-1);
- if (theDlog != NULL)
- {
- short itemType;
-
- GetDialogItem(theDlog, kMsgItemID, &itemType, &item, &box);
- if (item != NULL)
- {
- short itemHit;
-
- SetDialogItemText(item, theMsg);
- ModalDialog(NULL, &itemHit);
- DisposeDialog(theDlog);
- }
- }
-
- free(theMsg);
- }
- #endif
-
- /************************************************************
- * *
- * FUNCTION: Utils_Win32_DisplayMsg *
- * *
- * PURPOSE: Displays error messages for Win95/NT sample *
- * code *
- * *
- *************************************************************/
-
- #if TARGET_OS_WIN32
- static void Utils_Win32_DisplayMsg(char *msg)
- {
-
- MessageBox(NULL, msg, "", MB_OK);
- }
- #endif
-